package 剑指offer.Month7_07.day14;

import java.util.ArrayList;

public class 二叉树中和为某一值的路径2 {
    ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
    ArrayList<Integer> list = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root, int expectNumber) {
        if(root == null) return lists;
        solve(root,expectNumber);
        return lists;
    }

    public void solve(TreeNode root,int num){
        list.add(root.val);
        num -= root.val;
        if(root.left == null && root.right == null && num == 0) {
            lists.add(new ArrayList<>(list));
        }
        if(root.left != null) solve(root.left,num);
        if(root.right != null) solve(root.right,num);
        list.remove(list.size() - 1);
    }
}
